<template>
  <div class="detail-overlay" @click="closePanel">
    <div class="detail-panel" @click.stop>
      <div class="panel-header">
        <h2 class="panel-title">审计项目详细进度</h2>
        <button class="close-btn" @click="closePanel">✕</button>
      </div>
      
      <div class="panel-body">
        <div class="project-table">
          <div class="table-header">
            <div class="col col-name">项目名称</div>
            <div class="col col-year">年度</div>
            <div class="col col-stage">阶段</div>
            <div class="col col-progress">完成度</div>
            <div class="col col-leader">组长</div>
            <div class="col col-auditor">业务主审</div>
            <div class="col col-member">成员</div>
          </div>
          
          <div class="table-body">
            <div 
              v-for="(project, index) in sortedProjects" 
              :key="index"
              class="table-row"
              :class="getProgressClass(project.value)"
            >
              <div class="col col-name" :title="project.name">{{ project.name }}</div>
              <div class="col col-year">{{ project.prjYear }}</div>
              <div class="col col-stage">
                <span class="stage-badge">{{ project.linkName }}</span>
              </div>
              <div class="col col-progress">
                <div class="progress-cell">
                  <div class="progress-bar-mini">
                    <div 
                      class="progress-fill-mini" 
                      :style="{ width: `${project.value}%` }"
                    ></div>
                  </div>
                  <span class="progress-text">{{ project.value.toFixed(1) }}%</span>
                </div>
              </div>
              <div class="col col-leader">{{ project.leaderName || '-' }}</div>
              <div class="col col-auditor">{{ project.busRefereeName || '-' }}</div>
              <div class="col col-member" :title="project.member">{{ project.member || '-' }}</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { computed } from 'vue'

const props = defineProps({
  projects: {
    type: Array,
    default: () => []
  }
})

const emit = defineEmits(['close'])

// 按完成度从高到低排序
const sortedProjects = computed(() => {
  return [...props.projects].sort((a, b) => b.value - a.value)
})

// 根据完成度返回样式类
const getProgressClass = (progress) => {
  if (progress >= 80) return 'high-progress'
  if (progress >= 50) return 'medium-progress'
  return 'low-progress'
}

const closePanel = () => {
  emit('close')
}
</script>

<style scoped>
.detail-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.detail-panel {
  background: linear-gradient(135deg, #0a1e3e 0%, #0d2847 100%);
  border-radius: 12px;
  width: 90%;
  max-width: 1400px;
  height: 85vh;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(41, 217, 213, 0.3);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 30px;
  border-bottom: 2px solid rgba(41, 217, 213, 0.3);
}

.panel-title {
  color: #29D9D5;
  font-size: 20px;
  font-weight: bold;
  margin: 0;
}

.close-btn {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.close-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: rotate(90deg);
}

.panel-body {
  flex: 1;
  overflow: hidden;
  padding: 20px 30px;
  min-height: 0;
}

.project-table {
  height: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.table-header {
  display: flex;
  background: rgba(41, 217, 213, 0.1);
  border-radius: 6px;
  padding: 12px 15px;
  margin-bottom: 10px;
  border: 1px solid rgba(41, 217, 213, 0.3);
}

.table-body {
  flex: 1;
  overflow-y: scroll;
  padding-right: 10px;
  min-height: 0;
  scrollbar-width: thin;
  scrollbar-color: #29D9D5 rgba(255, 255, 255, 0.1);
}

/* Chrome, Safari, Edge */
.table-body::-webkit-scrollbar {
  width: 12px;
}

.table-body::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  margin: 5px 0;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.table-body::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #29D9D5 0%, #4ECDC4 100%);
  border-radius: 6px;
  border: 2px solid rgba(10, 30, 60, 0.5);
  box-shadow: 0 0 6px rgba(41, 217, 213, 0.3);
}

.table-body::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, #4ECDC4 0%, #5BE9E0 100%);
  box-shadow: 0 0 10px rgba(41, 217, 213, 0.6);
  border-color: rgba(10, 30, 60, 0.7);
}

.table-body::-webkit-scrollbar-thumb:active {
  background: #29D9D5;
}

.table-row {
  display: flex;
  padding: 12px 15px;
  margin-bottom: 8px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 6px;
  transition: all 0.3s ease;
  border-left: 3px solid transparent;
}

.table-row:hover {
  background: rgba(255, 255, 255, 0.08);
  transform: translateX(5px);
}

.table-row.high-progress {
  border-left-color: #91CC75;
}

.table-row.medium-progress {
  border-left-color: #FAC858;
}

.table-row.low-progress {
  border-left-color: #EE6666;
}

.col {
  color: #fff;
  font-size: 12px;
  padding: 0 8px;
  display: flex;
  align-items: center;
}

.table-header .col {
  color: #29D9D5;
  font-weight: bold;
  font-size: 13px;
}

.col-name {
  flex: 0 0 25%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.col-year {
  flex: 0 0 6%;
  justify-content: center;
}

.col-stage {
  flex: 0 0 10%;
  justify-content: center;
}

.col-progress {
  flex: 0 0 15%;
}

.col-leader {
  flex: 0 0 10%;
}

.col-auditor {
  flex: 0 0 10%;
}

.col-member {
  flex: 0 0 24%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stage-badge {
  background: rgba(41, 217, 213, 0.2);
  color: #29D9D5;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 11px;
  border: 1px solid rgba(41, 217, 213, 0.4);
}

.progress-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
}

.progress-bar-mini {
  flex: 1;
  height: 8px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill-mini {
  height: 100%;
  background: linear-gradient(90deg, #29D9D5 0%, #4ECDC4 100%);
  border-radius: 4px;
  transition: width 0.3s ease;
}

.high-progress .progress-fill-mini {
  background: linear-gradient(90deg, #91CC75 0%, #a8d88a 100%);
}

.medium-progress .progress-fill-mini {
  background: linear-gradient(90deg, #FAC858 0%, #ffd57a 100%);
}

.low-progress .progress-fill-mini {
  background: linear-gradient(90deg, #EE6666 0%, #ff8484 100%);
}

.progress-text {
  color: #29D9D5;
  font-weight: bold;
  font-size: 12px;
  min-width: 45px;
}
</style>
